# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html

import time

class WeatherPipeline(object):
    def process_item(self, item, spider):
        print '-----------------file----------------------'
        today = time.strftime('%Y%m%d', time.localtime())
        filename = today + '.txt'
        try:
            with open(filename, 'a') as fp:
                # print item['week'].encode('utf8')
                fp.write(item['week'].encode('utf8') + '\t')
                fp.write(item['weather'].encode('utf8') + '\t\t')
                fp.write(item['temperature'][0].encode('utf8') + "℃ ~ ")
                fp.write(item['temperature'][1].encode('utf8') + '\t')
                fp.write(item['wind'].encode('utf8') + '\n')
        except:
            print 'open file error'

        print '-----------------file--end--------------------'
        return item
